<?php
namespace app\common\model;

use think\Config;
use think\Db;
use think\Model;

class Shop extends Model{


    protected $table = "jiujiu_shop";


    public function getOwnerShop($owner){
        return $this->where('owner',$owner)->find();
    }


    public function saveShop($owner,$name,$phone,$img){
        if($img){
            $img = upload($img);
        }
        $shop = $this->where('owner',$owner)->find();
        if($shop){
            $shop->name = $name;
            $shop->img = $img;
            $shop->phone = $phone;
            $shop->save();
        }
        else{
          $this->insert([
                'owner'=>$owner,
                'name'=>$name,
                'img'=>$img,
                'phone'=>$phone,
                'createTime'=>time(),
            ]);
        }
    }


    public function getHomeShopInfo($id){
        $info = $this->where('id',$id)->find();
        $productCount = model('shop_product')->where('shopId',$id)->count();
        return ['info'=>$info,'productCount'=>$productCount];
    }







}